using System;
using System.Collections.Generic;
using csvviewer.contracts;

namespace csvviewer.logic
{
	public class Get_page_line_positions_from_buffer : IDependsOn<ConcurrentList<long>>
    {
        public void Process(Tuple<int,int, PageInfo> pageIndex)
        {
			var pageLinePositions = new List<long>();
			
			pageLinePositions.Add(_lineBuffer[0]);
			
			var n = pageIndex.Item2;
			if (pageIndex.Item1+n > _lineBuffer.Count) n = _lineBuffer.Count-pageIndex.Item1;
			pageLinePositions.AddRange(_lineBuffer.GetRange(pageIndex.Item1, n));
            
			this.Page(new PageOfLinePositions{LinePositions=pageLinePositions, PageInfo=pageIndex.Item3});
        }


        public event Action<PageOfLinePositions> Page;


        private ConcurrentList<long> _lineBuffer;

        public void Inject(ConcurrentList<long> dependency)
        {
            _lineBuffer = dependency;
        }
    }
}

